<?php

	if(!defined('YMT')) exit;

	/**
	 * @package Yomm
	 * @author bsuter
	 *
	 * Keeps the current server instance from MySQLi for each kind of
	 * class inside of the Yomm_Db.
	 */
	Abstract Class Yomm_Db_Server {
		
		static public $mysqli = null;
		
		/**
		 * connect to sql service and database with method connect
		 * @param $server
		 * @param $user
		 * @param $password
		 * @param $database
		 * @return boolean
		 */
		public function connect($server, $user, $password, $database)
		{
			if(!is_null(self::$mysqli))
				return;
			
			if(!class_exists('mysqli'))
				throw new Yomm_Error("MySQLi class does not exists on this server!");

			// connect to mysqli with credentials in site_config.php
			self::$mysqli = new mysqli($server, $user, $password, $database);
			
			if(!empty(self::$mysqli->error))
				throw new Yomm_Error("MySQLi connection Error: ". self::$mysqli->connect_error);
			
			return true;
		}
		
	}